package zhh;

import zhh.operate.SwitchOperate;
import zhh.operate.impl.HighSpeedRoadSwitchOperate;
import zhh.operate.impl.LowSpeedRoadSwitchOperate;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 粥灰灰
 * 2025/1/24 23:18
 * 这是一条路，负责进行车辆分流
 * 按照不同的车牌号进行分流
 */
public class RoadSwitch {

    private final Map<Integer, SwitchOperate> strategy;

    public RoadSwitch() {
        System.out.println("------------------ 来到了关卡 ------------------");
        this.strategy = new HashMap<>() {{
            put(0, new HighSpeedRoadSwitchOperate());
            put(1, new LowSpeedRoadSwitchOperate());
        }};
    }

    public void switchCar(RoadCar car) {
        System.out.printf("车辆[%d]来到了关卡%n", car.getCarSign());
        Map<Integer, SwitchOperate> strategy = this.strategy;
        SwitchOperate operate = strategy.get(car.getCarSign() % strategy.size());
        operate.switchCar(car);
    }
}
